package com.code.generator.provider;


import com.code.generator.context.velocity.VelocityGeneratorContext;
import com.code.generator.code.impl.ControllerGenerator;
import com.code.generator.code.impl.EntityGenerator;
import com.code.generator.code.impl.FilterGenerator;
import com.code.generator.code.impl.MapperGenerator;
import com.code.generator.code.impl.MapperXmlGenerator;
import com.code.generator.code.impl.ModelGenerator;
import com.code.generator.code.impl.PaginationRequestGenerator;
import com.code.generator.code.impl.PersistenceGenerator;
import com.code.generator.code.impl.QueryRequestGenerator;
import com.code.generator.code.impl.RepositoryGenerator;
import com.code.generator.code.impl.RepositoryImplGenerator;
import com.code.generator.code.impl.RequestGenerator;
import com.code.generator.code.impl.ServiceGenerator;
import com.code.generator.code.impl.ServiceImplGenerator;
import com.code.generator.code.impl.TesterGenerator;
import com.code.generator.code.impl.web.ApiJsGenerator;
import com.code.generator.code.impl.web.IndexGenerator;

import java.io.IOException;

public class CodeGenerateProvider implements com.code.generator.code.CodeGenerateProvider<VelocityGeneratorContext> {

    private String xmlSubDir;

    public String getXmlSubDir() {
        return xmlSubDir;
    }

    public void setXmlSubDir(String xmlSubDir) {
        this.xmlSubDir = xmlSubDir;
    }

    @Override
    public void generatePersistence(VelocityGeneratorContext context) throws IOException {
        PersistenceGenerator persistenceGenerator = new PersistenceGenerator();
        persistenceGenerator.generate(context);
    }

    @Override
    public void generateModel(VelocityGeneratorContext context) throws IOException {
        ModelGenerator modelGenerator = new ModelGenerator();
        modelGenerator.generate(context);
    }

    @Override
    public void generateFilter(VelocityGeneratorContext context) throws IOException {
        FilterGenerator filterGenerator = new FilterGenerator();
        filterGenerator.generate(context);
    }

    @Override
    public void generateEntity(VelocityGeneratorContext context) throws IOException {
        EntityGenerator entityGenerator = new EntityGenerator();
        entityGenerator.generate(context);
    }

    @Override
    public void generateMapper(VelocityGeneratorContext context) throws IOException {
        MapperGenerator mapperGenerator = new MapperGenerator();
        mapperGenerator.generate(context);
    }

    @Override
    public void generateMapperXml(VelocityGeneratorContext context) throws IOException {
        MapperXmlGenerator mapperXmlGenerator = new MapperXmlGenerator();
        mapperXmlGenerator.setSubDirName(xmlSubDir);
        mapperXmlGenerator.generate(context);
    }

    @Override
    public void generateRepository(VelocityGeneratorContext context) throws IOException {
        RepositoryGenerator repositoryGenerator = new RepositoryGenerator();
        repositoryGenerator.generate(context);
    }

    @Override
    public void generateRepositoryImpl(VelocityGeneratorContext context) throws IOException {
        RepositoryImplGenerator repositoryImplGenerator = new RepositoryImplGenerator();
        repositoryImplGenerator.generate(context);
    }

    @Override
    public void generateService(VelocityGeneratorContext context) throws IOException {
        ServiceGenerator serviceGenerator = new ServiceGenerator();
        serviceGenerator.generate(context);
    }

    @Override
    public void generateServiceImpl(VelocityGeneratorContext context) throws IOException {
        ServiceImplGenerator serviceImplGenerator = new ServiceImplGenerator();
        serviceImplGenerator.generate(context);
    }

    @Override
    public void generateRequest(VelocityGeneratorContext context) throws IOException {
        RequestGenerator requestGenerator = new RequestGenerator();
        requestGenerator.generate(context);
    }

    @Override
    public void generateQueryRequest(VelocityGeneratorContext context) throws IOException {
        QueryRequestGenerator queryRequestGenerator = new QueryRequestGenerator();
        queryRequestGenerator.generate(context);
    }

    @Override
    public void generatePaginationRequest(VelocityGeneratorContext context) throws IOException {
        PaginationRequestGenerator paginationRequestGenerator = new PaginationRequestGenerator();
        paginationRequestGenerator.generate(context);
    }

    @Override
    public void generateController(VelocityGeneratorContext context) throws IOException {
        ControllerGenerator controllerGenerator = new ControllerGenerator();
        controllerGenerator.generate(context);
    }

    @Override
    public void generateApiJs(VelocityGeneratorContext context) throws IOException {
        ApiJsGenerator apiJsGenerator = new ApiJsGenerator();
        apiJsGenerator.generate(context);
    }

    @Override
    public void generateIndex(VelocityGeneratorContext context) throws IOException {
        IndexGenerator indexGenerator = new IndexGenerator();
        indexGenerator.generate(context);
    }

    public void generateTester(VelocityGeneratorContext context) throws IOException {
        TesterGenerator testerGenerator = new TesterGenerator();
        testerGenerator.generate(context);
    }
}
